﻿#pragma once

#include "../MirEnvir/Envir.h"
#include "../../Shared/Enums.h"
#include "../../Shared/Packet.h"
#include "../../Shared/Data/ClientData.h"
#include <string>
#include <cmath>
#include "../../bankersrounding.h"

using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirDatabase
{
    class MagicInfo
    {
    protected:
        static Server::MirEnvir::Envir *getEnvir();

    public:
        std::string Name;
        Spell Spell = static_cast<Spell>(0);
        unsigned char BaseCost = 0, LevelCost = 0, Icon = 0;
        unsigned char Level1 = 0, Level2 = 0, Level3 = 0;
        unsigned short Need1 = 0, Need2 = 0, Need3 = 0;
        unsigned int DelayBase = 1800, DelayReduction = 0;
        unsigned short PowerBase = 0, PowerBonus = 0;
        unsigned short MPowerBase = 0, MPowerBonus = 0;
        float MultiplierBase = 1.0f, MultiplierBonus = 0;
        unsigned char Range = 9;

        std::string ToString();

        MagicInfo();

        MagicInfo(BinaryReader *reader, int version = int::MaxValue, int Customversion = int::MaxValue);

        void Save(BinaryWriter *writer);
    };

    class UserMagic
    {
    public:
        virtual ~UserMagic()
        {
            delete Info;
        }

    protected:
        static Server::MirEnvir::Envir *getEnvir();

    public:
        Spell Spell = static_cast<Spell>(0);
        MagicInfo *Info;

        unsigned char Level = 0, Key = 0;
        unsigned short Experience = 0;
        bool IsTempSpell = false;
        long long CastTime = 0;

    private:
        MagicInfo *GetMagicInfo(Spell spell);

    public:
        UserMagic(Spell spell);
        UserMagic(BinaryReader *reader);
        void Save(BinaryWriter *writer);

        Packet *GetInfo();

        ClientMagic *CreateClientMagic();

        int GetDamage(int DamageBase);

        float GetMultiplier();

        int GetPower();

        int MPower();
        int DefPower();

        int GetPower(int power);

        long long GetDelay();
    };
}
